package com.tjsinfo.tjsoa.oldOADocument.shouwen.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.oldOADocument.shouwen.bo.ITChaYueWenJianBO;
import com.tjsinfo.tjsoa.oldOADocument.shouwen.vo.ShouWenInfo;
/**
 * 原oa发文查阅文件
 * @author wangjingjing
 *
 */
public class oldChaYueWenJianAction extends Action{
	private ITChaYueWenJianBO chayuewenjianBO;
	
	public ITChaYueWenJianBO getChayuewenjianBO() {
		return chayuewenjianBO;
	}

	public void setChayuewenjianBO(ITChaYueWenJianBO chayuewenjianBO) {
		this.chayuewenjianBO = chayuewenjianBO;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		
//		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.ss");   //调试用
				
		Integer first =  0;
		String shouwenbianhao = request.getParameter("shouwenbianhao");
		String laiwenbiaoti = request.getParameter("laiwenbiaoti");
		String laiwenzihao = request.getParameter("laiwenzihao");
		String laiwenjiguan = request.getParameter("laiwenjiguan");
		String maintypeid = request.getParameter("maintypeid");
		List<ShouWenInfo> shouWenInfoList = new ArrayList<ShouWenInfo>();
		
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		
//		Calendar ctemp = Calendar.getInstance();    //调试用
//        System.out.println(df.format(ctemp.getTime())+"开始查询前20个文件");     //调试用
        
		if (request.getParameter("start") == null) {
			shouWenInfoList = chayuewenjianBO.selectChaYueWenJian(0, (0 + 20), laiwenbiaoti, shouwenbianhao, laiwenzihao,laiwenjiguan,maintypeid);
		} else {
			 first = Integer.parseInt(request.getParameter("start"));
			shouWenInfoList =  chayuewenjianBO.selectChaYueWenJian((first + 1), (first + 20) ,laiwenbiaoti, shouwenbianhao, laiwenzihao,laiwenjiguan,maintypeid);
		}
		
//	    ctemp = Calendar.getInstance();    //调试用
//        System.out.println(df.format(ctemp.getTime())+"开始查询文件数");     //调试用
        
		Integer totalProperty = chayuewenjianBO.selectChaYueWenJianCount( laiwenbiaoti, shouwenbianhao, laiwenzihao,laiwenjiguan,maintypeid);		
		object.put("totalProperty", totalProperty);
		
//		ctemp = Calendar.getInstance();    //调试用
//	    System.out.println(df.format(ctemp.getTime())+"开始赋值");     //调试用
		
	   for (ShouWenInfo shouWenInfo : shouWenInfoList) {
			if(shouWenInfo.getId() != null){
				JSONObject object2 = new JSONObject(shouWenInfo);
//				object2.put("operate", "<a href='"+basePath+"/tjsinfo/tjsoa/oldoa/fawenview.do?id="+shouWenInfo.getId()+"' target='_blank'>查看附件</a>");
				array.put(object2);
			}
		}
		object.put("root", array);
		
//		 ctemp = Calendar.getInstance();    //调试用
//	     System.out.println(df.format(ctemp.getTime())+"返回结果");     //调试用
		response.getWriter().print(object);
		return null;
	}
	
}

